package com.wenchao.libwifi;

import static com.wenchao.libwifi.bean.WifiBean.WifiLevel.LEVEL1;

import android.net.wifi.ScanResult;

import com.wenchao.libwifi.bean.WifiBean;

/**
 * 【类的描述】介绍一下该类的用途
 *
 * @author zhangwenchao
 * @date 2022-02-15
 */
public class WifiUtils {

    public static EncryptType getEncryptType(ScanResult scanResult) {
        if (scanResult == null) {
            return null;
        }
        String str = scanResult.capabilities.toLowerCase();
        if (str.contains("wpa")) {
            return EncryptType.WPA;
        } else if (str.contains("wep")) {
            return EncryptType.WEP;
        } else {
            return EncryptType.OPEN;
        }
    }

    /**
     * 优秀> -50 dBm 4
     * 好的-50至-60 dBm 3
     * 正常-60至-70 dBm 2
     * 弱<-70 dBm 1
     *
     * @param level
     * @return
     */
    public static WifiBean.WifiLevel getLevel(int level) {
        if (level > -50) {
            return WifiBean.WifiLevel.LEVEL_FULL;
        } else if (level > -60) {
            return WifiBean.WifiLevel.LEVEL3;
        } else if (level > -70) {
            return WifiBean.WifiLevel.LEVEL2;
        } else {
            return WifiBean.WifiLevel.LEVEL1;
        }
    }

}
